//
//  WelcomeViewController.swift
//  XMGWB
//
//  Created by 1 on 16/1/11.
//  Copyright © 2016年 xiaomage. All rights reserved.
//

import UIKit
import SDWebImage

class WelcomeViewController: UIViewController {

    /// 头像底部约束
    @IBOutlet weak var iconBottomCons: NSLayoutConstraint!
    /// 欢迎回来文本
    @IBOutlet weak var titleLabel: UILabel!
    /// 头像容器
    @IBOutlet weak var iconImageView: UIImageView!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // 设置用户头像
        let urlStr = UserAccount.loadUserAccount()?.avatar_large
//        CBWLog(urlStr)
        let url = NSURL(string: urlStr ?? "")
        iconImageView.sd_setImageWithURL(url, placeholderImage: UIImage(named: "avatar_default_big"))
    }
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        
        // 计算偏移位
        let offsetY = UIScreen.mainScreen().bounds.height - iconBottomCons.constant
        iconBottomCons.constant = offsetY
        // 执行动画
        UIView.animateWithDuration(1.0, animations: { () -> Void in
             self.view.layoutIfNeeded()
            }) { (_) -> Void in
                UIView.animateWithDuration(1.0, animations: { () -> Void in
                    self.titleLabel.alpha = 1.0
                    }, completion: { (_) -> Void in
                      
                        NSNotificationCenter.defaultCenter().postNotificationName(CBWChangeRootViewControllerNotification, object: self, userInfo: ["message": true])
                })
        }
    }
}
